// pages/addAccount/addAccount.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tripid: "",
        date: "",
        timeStamp: 0,
        currentClassifi: 6,
        name: "",
        note: "",
        amount: 0.0,
        classifi: [{
            id: 0,
            name: "景点",
            icon: "/images/classifi/classifi0.png"
        },{
            id: 1,
            name: "购物",
            icon: "/images/classifi/classifi1.png"
        },{
            id: 2,
            name: "美食",
            icon: "/images/classifi/classifi2.png"
        },{
            id: 3,
            name: "活动",
            icon: "/images/classifi/classifi3.png"
        },{
            id: 4,
            name: "交通",
            icon: "/images/classifi/classifi4.png"
        },{
            id: 5,
            name: "住宿",
            icon: "/images/classifi/classifi5.png"
        },{
            id: 6,
            name: "其他",
            icon: "/images/classifi/classifi6.png"
        }]
    },

    bindDateChange: function(e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
          date: e.detail.value,
          timeStamp: Date.parse(e.detail.value)
        })
      },

    getClassifi: function (e) {
        console.log(e.currentTarget.dataset.classid)
        this.setData({
            currentClassifi: e.currentTarget.dataset.classid
          })
    },

    getDate: function (date) {
        var now = new Date(date)
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth(); //得到月份
        var date = now.getDate(); //得到日期
        month = month + 1;
        if (month < 10) month = "0" + month;
        if (date < 10) date = "0" + date;
        var strtime = "";
        strtime = year + "-" + month + "-" + date
        return strtime
    },
    getNote: function (e) {
        this.setData({
            note: e.detail.value
        })

    },
    getTitle: function (e) {
        this.setData({
            name: e.detail.value
        })
    },
    getAmount: function name(e) {
        this.setData({
            amount: parseFloat(e.detail.value)
        })
    },

    submitAcc:function () {
        wx.cloud.callFunction({
            name: 'addAccountRecord',
            data:{
                tripid: this.data.tripid,
                name: this.data.name,
                classifi: this.data.currentClassifi,
                timeStamp: this.data.timeStamp,
                note: this.data.note,
                amount: this.data.amount
            }
        }).then(res => {
            console.log("add done")
            wx.navigateBack({
              delta: 1,
            })
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        var now = new Date(new Date().setHours(8,0,0,0))
        this.setData({
            timeStamp: now.getTime(),
            date: this.getDate(now),
            tripid: e.tripId
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})